package cn.egame.file.util;

import java.util.Properties;

import cn.egame.common.util.Utils;

public class ConstVar {
    public static final int RANK = 900;
    public static final int APPID = 905;
    public static final int WEBID = 706;

    public static final int GAME_STATUS_ON_LINE = 6;

    public static String MAX_ID_FILE_PATH;
    public static String MAX_ID_URL;
    public static String DNS_HOST;
    public static String EFS_TYPE;
    public static String NUM;
    public static String LOCAL_FILE_PATH;
    public static int REPEAT_READ_NUM;

    static {
        Properties properties = getProperties();
        MAX_ID_FILE_PATH = getPropertiesValueByKey(properties, "max_id_file_path", MAX_ID_FILE_PATH);
        System.out.println("max_id_file_path========" + MAX_ID_FILE_PATH);

        MAX_ID_URL = getPropertiesValueByKey(properties, "max_id_url", MAX_ID_URL);
        System.out.println("max_id_url========" + MAX_ID_URL);

        DNS_HOST = getPropertiesValueByKey(properties, "dns_host", DNS_HOST);
        System.out.println("dns_host========" + DNS_HOST);

        EFS_TYPE = getPropertiesValueByKey(properties, "efs_type", EFS_TYPE);
        System.out.println("efs_type========" + EFS_TYPE);

        NUM = getPropertiesValueByKey(properties, "num", NUM);
        System.out.println("num========" + NUM);

        LOCAL_FILE_PATH = getPropertiesValueByKey(properties, "local_file_path", LOCAL_FILE_PATH);
        System.out.println("local_file_path========" + LOCAL_FILE_PATH);

        REPEAT_READ_NUM = getPropertiesIntValueByKey(properties, "repeat_read_num", REPEAT_READ_NUM);
        System.out.println("repeat_read_num========" + REPEAT_READ_NUM);
    }

    private static String getPropertiesValueByKey(Properties properties, String key, String defaultResult) {
        /* download_url 获取 */
        String value = properties.getProperty(key);
        if (value != null && !"".equals(value.trim())) {
            return value;
        }
        return defaultResult;
    }

    private static int getPropertiesIntValueByKey(Properties properties, String key, int defaultResult) {
        /* download_url 获取 */
        String value = properties.getProperty(key);
        if (value != null && !"".equals(value.trim()) && value.matches("\\d+")) {
            return Integer.parseInt(value);
        }
        return defaultResult;
    }

    private static Properties getProperties() {
        Properties properties = new Properties();
        try {
            properties = Utils.getProperties("common.properties");
        } catch (Exception e) {
            System.out.println("common.properties not find");
        }
        return properties;
    }
}
